package logic

import (
	"context"
	"novel-sys/goods/goods"

	"novel-sys/api/internal/svc"
	"novel-sys/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type NovelList2ApiLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewNovelList2ApiLogic(ctx context.Context, svcCtx *svc.ServiceContext) *NovelList2ApiLogic {
	return &NovelList2ApiLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *NovelList2ApiLogic) NovelList2Api(req *types.NovelList2Request) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	list, err := l.svcCtx.GoodsRpc.NovelList2(l.ctx, &goods.NovelList2Request{
		Page:  req.Page,
		Size:  req.Size,
		Title: req.Title,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Data:    nil,
			Code:    500,
		}, nil
	}
	return &types.Response{
		Message: "查询成功",
		Data:    list,
		Code:    200,
	}, nil
}
